<?php

namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable

{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function testUser(){
//        return $this->findOrFail(3);
        return $this->where('id','>',1)->get();
    }

    public function userAdd()
    {
        $userdata =['name'=>'haohao','email'=>'67288182@qq.com','password'=>bcrypt('allen0521')];

//        $this->name = 'tata1';
//        $this->email = '6667277@qq.com';
//        $this->password = bcrypt('allen0521');
        $this->fill($userdata);
        $this->save();
    }

    public function  updateUser()
    {
        //直接找出记录集修改全部
//          $xgUser = $this->where('name','like','tata%');
//          $xgUser->update(['name'=>'zhanghutata',]);
          //直接找出单个修改
//        $xgUser = $this->find(7);
//        $xgUser->name = 'zhanghuhaohao';
        //save() 对单个保存，多个保存不需要save()
//        $xgUser->save();
    }

    public function userDel()
    {
        $user = $this->find(4);
        $user->delete();
    }
}
